

<!DOCTYPE html>
<html class="writer-html5" lang="en" >
<head>
  <meta charset="utf-8" />
  
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  
  <title>mindspore.ops.operations.debug_ops &mdash; MindSpore master documentation</title>
  

  
  <link rel="stylesheet" href="../../../../_static/css/theme.css" type="text/css" />
  <link rel="stylesheet" href="../../../../_static/pygments.css" type="text/css" />

  
  

  
  

  

  
  <!--[if lt IE 9]>
    <script src="../../../../_static/js/html5shiv.min.js"></script>
  <![endif]-->
  
    
      <script type="text/javascript" id="documentation_options" data-url_root="../../../../" src="../../../../_static/documentation_options.js"></script>
        <script src="../../../../_static/jquery.js"></script>
        <script src="../../../../_static/underscore.js"></script>
        <script src="../../../../_static/doctools.js"></script>
        <script src="../../../../_static/language_data.js"></script>
        <script async="async" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/latest.js?config=TeX-AMS-MML_HTMLorMML"></script>
    
    <script type="text/javascript" src="../../../../_static/js/theme.js"></script>

    
    <link rel="index" title="Index" href="../../../../genindex.html" />
    <link rel="search" title="Search" href="../../../../search.html" /> 
</head>

<body class="wy-body-for-nav">

   
  <div class="wy-grid-for-nav">
    
    <nav data-toggle="wy-nav-shift" class="wy-nav-side">
      <div class="wy-side-scroll">
        <div class="wy-side-nav-search" >
          

          
            <a href="../../../../index.html" class="icon icon-home"> MindSpore
          

          
          </a>

          
            
            
          

          
<div role="search">
  <form id="rtd-search-form" class="wy-form" action="../../../../search.html" method="get">
    <input type="text" name="q" placeholder="Search docs" />
    <input type="hidden" name="check_keywords" value="yes" />
    <input type="hidden" name="area" value="default" />
  </form>
</div>

          
        </div>

        
        <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
          
            
            
              
            
            
              <p class="caption"><span class="caption-text">MindSpore Python API</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../../../api_python/mindspore.html">mindspore</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../api_python/mindspore.common.initializer.html">mindspore.common.initializer</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../api_python/mindspore.communication.html">mindspore.communication</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../api_python/mindspore.compression.html">mindspore.compression</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../api_python/mindspore.context.html">mindspore.context</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../api_python/mindspore.dataset.html">mindspore.dataset</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../api_python/mindspore.dataset.audio.html">mindspore.dataset.audio</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../api_python/mindspore.dataset.config.html">mindspore.dataset.config</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../api_python/mindspore.dataset.text.html">mindspore.dataset.text</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../api_python/mindspore.dataset.transforms.html">mindspore.dataset.transforms</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../api_python/mindspore.dataset.vision.html">mindspore.dataset.vision</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../api_python/mindspore.mindrecord.html">mindspore.mindrecord</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../api_python/mindspore.nn.html">mindspore.nn</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../api_python/mindspore.nn.probability.html">mindspore.nn.probability</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../api_python/mindspore.nn.transformer.html">mindspore.nn.transformer</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../api_python/mindspore.numpy.html">mindspore.numpy</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../api_python/mindspore.ops.html">mindspore.ops</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../api_python/mindspore.parallel.html">mindspore.parallel</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../api_python/mindspore.parallel.nn.html">mindspore.parallel.nn</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../api_python/mindspore.profiler.html">mindspore.profiler</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../api_python/mindspore.scipy.html">mindspore.scipy</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../api_python/mindspore.train.html">mindspore.train</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../api_python/mindspore.boost.html">mindspore.boost</a></li>
</ul>
<p class="caption"><span class="caption-text">MindSpore C++ API</span></p>
<ul>
<li class="toctree-l1"><a class="reference external" href="https://www.mindspore.cn/lite/api/zh-CN/master/api_cpp/mindspore.html">MindSpore Lite↗</a></li>
</ul>

            
          
        </div>
        
      </div>
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">

      
      <nav class="wy-nav-top" aria-label="top navigation">
        
          <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
          <a href="../../../../index.html">MindSpore</a>
        
      </nav>


      <div class="wy-nav-content">
        
        <div class="rst-content">
        
          

















<div role="navigation" aria-label="breadcrumbs navigation">

  <ul class="wy-breadcrumbs">
    
      <li><a href="../../../../index.html" class="icon icon-home"></a> &raquo;</li>
        
          <li><a href="../../../index.html">Module code</a> &raquo;</li>
        
      <li>mindspore.ops.operations.debug_ops</li>
    
    
      <li class="wy-breadcrumbs-aside">
        
      </li>
    
  </ul>

  
  <hr/>
</div>
          <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
           <div itemprop="articleBody">
            
  <h1>Source code for mindspore.ops.operations.debug_ops</h1><div class="highlight"><pre>
<span></span><span class="c1"># Copyright 2020-2021 Huawei Technologies Co., Ltd</span>
<span class="c1">#</span>
<span class="c1"># Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);</span>
<span class="c1"># you may not use this file except in compliance with the License.</span>
<span class="c1"># You may obtain a copy of the License at</span>
<span class="c1">#</span>
<span class="c1"># http://www.apache.org/licenses/LICENSE-2.0</span>
<span class="c1">#</span>
<span class="c1"># Unless required by applicable law or agreed to in writing, software</span>
<span class="c1"># distributed under the License is distributed on an &quot;AS IS&quot; BASIS,</span>
<span class="c1"># WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.</span>
<span class="c1"># See the License for the specific language governing permissions and</span>
<span class="c1"># limitations under the License.</span>
<span class="c1"># ============================================================================</span>
<span class="sd">&quot;&quot;&quot;debug_ops&quot;&quot;&quot;</span>
<span class="kn">from</span> <span class="nn">types</span> <span class="kn">import</span> <span class="n">FunctionType</span><span class="p">,</span> <span class="n">MethodType</span>

<span class="kn">from</span> <span class="nn">mindspore</span> <span class="kn">import</span> <span class="n">context</span>
<span class="kn">from</span> <span class="nn">mindspore._c_expression</span> <span class="kn">import</span> <span class="n">security</span>
<span class="kn">from</span> <span class="nn">..._checkparam</span> <span class="kn">import</span> <span class="n">Validator</span> <span class="k">as</span> <span class="n">validator</span>
<span class="kn">from</span> <span class="nn">..._checkparam</span> <span class="kn">import</span> <span class="n">Rel</span>
<span class="kn">from</span> <span class="nn">...common</span> <span class="kn">import</span> <span class="n">dtype</span> <span class="k">as</span> <span class="n">mstype</span>
<span class="kn">from</span> <span class="nn">..primitive</span> <span class="kn">import</span> <span class="n">prim_attr_register</span><span class="p">,</span> <span class="n">Primitive</span><span class="p">,</span> <span class="n">PrimitiveWithInfer</span>


<span class="k">def</span> <span class="nf">_check_mode</span><span class="p">(</span><span class="n">class_name</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Check for PyNative mode.&quot;&quot;&quot;</span>
    <span class="n">mode</span> <span class="o">=</span> <span class="n">context</span><span class="o">.</span><span class="n">get_context</span><span class="p">(</span><span class="s1">&#39;mode&#39;</span><span class="p">)</span>
    <span class="k">if</span> <span class="n">mode</span> <span class="o">==</span> <span class="n">context</span><span class="o">.</span><span class="n">PYNATIVE_MODE</span><span class="p">:</span>
        <span class="k">raise</span> <span class="ne">RuntimeError</span><span class="p">(</span><span class="sa">f</span><span class="s2">&quot;For &#39;</span><span class="si">{</span><span class="n">class_name</span><span class="si">}</span><span class="s2">&#39;, the operator does not support PyNative mode.&quot;</span><span class="p">)</span>


<span class="k">def</span> <span class="nf">_check_summary_param</span><span class="p">(</span><span class="n">name</span><span class="p">,</span> <span class="n">value</span><span class="p">,</span> <span class="n">class_name</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Checks the name and value is valid for summary.&quot;&quot;&quot;</span>
    <span class="n">_check_mode</span><span class="p">(</span><span class="n">class_name</span><span class="p">)</span>
    <span class="n">n_type</span> <span class="o">=</span> <span class="n">name</span><span class="p">[</span><span class="s1">&#39;dtype&#39;</span><span class="p">]</span>
    <span class="n">n_value</span> <span class="o">=</span> <span class="n">name</span><span class="p">[</span><span class="s1">&#39;value&#39;</span><span class="p">]</span>
    <span class="n">validator</span><span class="o">.</span><span class="n">check_value_type</span><span class="p">(</span><span class="s1">&#39;name&#39;</span><span class="p">,</span> <span class="n">n_type</span><span class="p">,</span> <span class="p">[</span><span class="nb">type</span><span class="p">(</span><span class="n">mstype</span><span class="o">.</span><span class="n">string</span><span class="p">)],</span> <span class="n">class_name</span><span class="p">)</span>
    <span class="k">if</span> <span class="ow">not</span> <span class="n">n_value</span><span class="p">:</span>
        <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="sa">f</span><span class="s2">&quot;For &#39;</span><span class="si">{</span><span class="n">class_name</span><span class="si">}</span><span class="s2">&#39;, the name should be valid string, but got &#39;</span><span class="si">{</span><span class="n">n_value</span><span class="si">}</span><span class="s2">&#39;.&quot;</span><span class="p">)</span>

    <span class="n">v_type</span> <span class="o">=</span> <span class="n">value</span><span class="p">[</span><span class="s1">&#39;dtype&#39;</span><span class="p">]</span>
    <span class="n">validator</span><span class="o">.</span><span class="n">check_value_type</span><span class="p">(</span><span class="s1">&#39;value&#39;</span><span class="p">,</span> <span class="n">v_type</span><span class="p">,</span> <span class="p">[</span><span class="nb">type</span><span class="p">(</span><span class="n">mstype</span><span class="o">.</span><span class="n">tensor</span><span class="p">)],</span> <span class="n">class_name</span><span class="p">)</span>


<span class="c1"># Note: The return value of the summary operator is not used,</span>
<span class="c1"># so there&#39;s nothing special about the return `dtype` or `shape`, any value is ok.</span>
<span class="c1"># The `value` should be set to None, else summary operators may be optimized at compile graph phase,</span>
<span class="c1"># it cause summary operators can not record data in constant folding scene.</span>
<span class="n">SUMMARY_RETURN_VALUE</span> <span class="o">=</span> <span class="p">{</span><span class="s1">&#39;dtype&#39;</span><span class="p">:</span> <span class="n">mstype</span><span class="o">.</span><span class="n">int32</span><span class="p">,</span> <span class="s1">&#39;shape&#39;</span><span class="p">:</span> <span class="p">[</span><span class="mi">1</span><span class="p">],</span> <span class="s1">&#39;value&#39;</span><span class="p">:</span> <span class="kc">None</span><span class="p">}</span>


<div class="viewcode-block" id="ScalarSummary"><a class="viewcode-back" href="../../../../api_python/ops/mindspore.ops.ScalarSummary.html#mindspore.ops.ScalarSummary">[docs]</a><span class="k">class</span> <span class="nc">ScalarSummary</span><span class="p">(</span><span class="n">Primitive</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Outputs a scalar to a protocol buffer through a scalar summary operator.</span>

<span class="sd">    Inputs:</span>
<span class="sd">        - **name** (str) - The name of the input variable, it must not be an empty string.</span>
<span class="sd">        - **value** (Tensor) - The value of scalar, and the shape of value must be [] or [1].</span>

<span class="sd">    Raises:</span>
<span class="sd">        TypeError: If `name` is not a str.</span>
<span class="sd">        TypeError: If `value` is not a Tensor.</span>

<span class="sd">    Supported Platforms:</span>
<span class="sd">        ``Ascend`` ``GPU`` ``CPU``</span>

<span class="sd">    Examples:</span>
<span class="sd">        &gt;&gt;&gt; import mindspore.nn as nn</span>
<span class="sd">        &gt;&gt;&gt; import mindspore.ops as ops</span>
<span class="sd">        &gt;&gt;&gt;</span>
<span class="sd">        &gt;&gt;&gt;</span>
<span class="sd">        &gt;&gt;&gt; class SummaryDemo(nn.Cell):</span>
<span class="sd">        ...     def __init__(self,):</span>
<span class="sd">        ...         super(SummaryDemo, self).__init__()</span>
<span class="sd">        ...         self.summary = ops.ScalarSummary()</span>
<span class="sd">        ...         self.add = ops.Add()</span>
<span class="sd">        ...</span>
<span class="sd">        ...     def construct(self, x, y):</span>
<span class="sd">        ...         name = &quot;x&quot;</span>
<span class="sd">        ...         self.summary(name, x)</span>
<span class="sd">        ...         x = self.add(x, y)</span>
<span class="sd">        ...         return x</span>
<span class="sd">        ...</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="nd">@prim_attr_register</span>
    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Initialize ScalarSummary.&quot;&quot;&quot;</span>

        <span class="k">if</span> <span class="n">security</span><span class="o">.</span><span class="n">enable_security</span><span class="p">():</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s1">&#39;The Summary is not supported, please without `-s on` and recompile source.&#39;</span><span class="p">)</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">add_prim_attr</span><span class="p">(</span><span class="s2">&quot;side_effect_io&quot;</span><span class="p">,</span> <span class="kc">True</span><span class="p">)</span></div>


<div class="viewcode-block" id="ImageSummary"><a class="viewcode-back" href="../../../../api_python/ops/mindspore.ops.ImageSummary.html#mindspore.ops.ImageSummary">[docs]</a><span class="k">class</span> <span class="nc">ImageSummary</span><span class="p">(</span><span class="n">PrimitiveWithInfer</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Outputs the image tensor to protocol buffer through image summary operator.</span>

<span class="sd">    Inputs:</span>
<span class="sd">        - **name** (str) - The name of the input variable, it must not be an empty string.</span>
<span class="sd">        - **value** (Tensor) - The value of image, the rank of tensor must be 4.</span>

<span class="sd">    Raises:</span>
<span class="sd">        TypeError: If `name` is not a str.</span>
<span class="sd">        TypeError: If `value` is not a Tensor.</span>

<span class="sd">    Supported Platforms:</span>
<span class="sd">        ``Ascend`` ``GPU`` ``CPU``</span>

<span class="sd">    Examples:</span>

<span class="sd">        &gt;&gt;&gt; import mindspore.nn as nn</span>
<span class="sd">        &gt;&gt;&gt; import mindspore.ops as ops</span>
<span class="sd">        &gt;&gt;&gt;</span>
<span class="sd">        &gt;&gt;&gt;</span>
<span class="sd">        &gt;&gt;&gt; class Net(nn.Cell):</span>
<span class="sd">        ...     def __init__(self):</span>
<span class="sd">        ...         super(Net, self).__init__()</span>
<span class="sd">        ...         self.summary = ops.ImageSummary()</span>
<span class="sd">        ...</span>
<span class="sd">        ...     def construct(self, x):</span>
<span class="sd">        ...         name = &quot;image&quot;</span>
<span class="sd">        ...         out = self.summary(name, x)</span>
<span class="sd">        ...         return out</span>
<span class="sd">        ...</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="nd">@prim_attr_register</span>
    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Initialize ImageSummary.&quot;&quot;&quot;</span>

        <span class="k">if</span> <span class="n">security</span><span class="o">.</span><span class="n">enable_security</span><span class="p">():</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s1">&#39;The Summary is not supported, please without `-s on` and recompile source.&#39;</span><span class="p">)</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">add_prim_attr</span><span class="p">(</span><span class="s2">&quot;side_effect_io&quot;</span><span class="p">,</span> <span class="kc">True</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">__infer__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">name</span><span class="p">,</span> <span class="n">value</span><span class="p">):</span>
        <span class="n">_check_summary_param</span><span class="p">(</span><span class="n">name</span><span class="p">,</span> <span class="n">value</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="o">.</span><span class="vm">__name__</span><span class="p">)</span>

        <span class="c1"># The shape dim of image should be 4.</span>
        <span class="n">v_shape</span> <span class="o">=</span> <span class="n">value</span><span class="p">[</span><span class="s1">&#39;shape&#39;</span><span class="p">]</span>
        <span class="n">image_dim</span> <span class="o">=</span> <span class="mi">4</span>
        <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">v_shape</span><span class="p">)</span> <span class="o">!=</span> <span class="n">image_dim</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="sa">f</span><span class="s2">&quot;For &#39;</span><span class="si">{</span><span class="bp">self</span><span class="o">.</span><span class="n">name</span><span class="si">}</span><span class="s2">&#39;, the dimension of &#39;value&#39; should be </span><span class="si">{</span><span class="n">image_dim</span><span class="si">}</span><span class="s2">,&quot;</span>
                             <span class="sa">f</span><span class="s2">&quot; but got </span><span class="si">{</span><span class="nb">len</span><span class="p">(</span><span class="n">v_shape</span><span class="p">)</span><span class="si">}</span><span class="s2">.&quot;</span><span class="p">)</span>

        <span class="k">return</span> <span class="n">SUMMARY_RETURN_VALUE</span></div>


<div class="viewcode-block" id="TensorSummary"><a class="viewcode-back" href="../../../../api_python/ops/mindspore.ops.TensorSummary.html#mindspore.ops.TensorSummary">[docs]</a><span class="k">class</span> <span class="nc">TensorSummary</span><span class="p">(</span><span class="n">Primitive</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Outputs a tensor to a protocol buffer through a tensor summary operator.</span>

<span class="sd">    Inputs:</span>
<span class="sd">        - **name** (str) - The name of the input variable.</span>
<span class="sd">        - **value** (Tensor) - The value of tensor, and the rank of tensor must be greater than 0.</span>

<span class="sd">    Raises:</span>
<span class="sd">        TypeError: If `name` is not a str.</span>
<span class="sd">        TypeError: If `value` is not a Tensor.</span>

<span class="sd">    Supported Platforms:</span>
<span class="sd">        ``Ascend`` ``GPU`` ``CPU``</span>

<span class="sd">    Examples:</span>
<span class="sd">        &gt;&gt;&gt; import mindspore.nn as nn</span>
<span class="sd">        &gt;&gt;&gt; import mindspore.ops as ops</span>
<span class="sd">        &gt;&gt;&gt;</span>
<span class="sd">        &gt;&gt;&gt;</span>
<span class="sd">        &gt;&gt;&gt; class SummaryDemo(nn.Cell):</span>
<span class="sd">        ...     def __init__(self,):</span>
<span class="sd">        ...         super(SummaryDemo, self).__init__()</span>
<span class="sd">        ...         self.summary = ops.TensorSummary()</span>
<span class="sd">        ...         self.add = ops.Add()</span>
<span class="sd">        ...</span>
<span class="sd">        ...     def construct(self, x, y):</span>
<span class="sd">        ...         x = self.add(x, y)</span>
<span class="sd">        ...         name = &quot;x&quot;</span>
<span class="sd">        ...         self.summary(name, x)</span>
<span class="sd">        ...         return x</span>
<span class="sd">        ...</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="nd">@prim_attr_register</span>
    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Initialize TensorSummary.&quot;&quot;&quot;</span>

        <span class="k">if</span> <span class="n">security</span><span class="o">.</span><span class="n">enable_security</span><span class="p">():</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s1">&#39;The Summary is not supported, please without `-s on` and recompile source.&#39;</span><span class="p">)</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">add_prim_attr</span><span class="p">(</span><span class="s2">&quot;side_effect_io&quot;</span><span class="p">,</span> <span class="kc">True</span><span class="p">)</span></div>


<div class="viewcode-block" id="HistogramSummary"><a class="viewcode-back" href="../../../../api_python/ops/mindspore.ops.HistogramSummary.html#mindspore.ops.HistogramSummary">[docs]</a><span class="k">class</span> <span class="nc">HistogramSummary</span><span class="p">(</span><span class="n">PrimitiveWithInfer</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Outputs the tensor to protocol buffer through histogram summary operator.</span>

<span class="sd">    Inputs:</span>
<span class="sd">        - **name** (str) - The name of the input variable.</span>
<span class="sd">        - **value** (Tensor) - The value of tensor, and the rank of tensor must be greater than 0.</span>

<span class="sd">    Raises:</span>
<span class="sd">        TypeError: If `name` is not a str.</span>
<span class="sd">        TypeError: If `value` is not a Tensor.</span>

<span class="sd">    Supported Platforms:</span>
<span class="sd">        ``Ascend`` ``GPU`` ``CPU``</span>

<span class="sd">    Examples:</span>
<span class="sd">        &gt;&gt;&gt; import mindspore.nn as nn</span>
<span class="sd">        &gt;&gt;&gt; import mindspore.ops as ops</span>
<span class="sd">        &gt;&gt;&gt;</span>
<span class="sd">        &gt;&gt;&gt;</span>
<span class="sd">        &gt;&gt;&gt; class SummaryDemo(nn.Cell):</span>
<span class="sd">        ...     def __init__(self,):</span>
<span class="sd">        ...         super(SummaryDemo, self).__init__()</span>
<span class="sd">        ...         self.summary = ops.HistogramSummary()</span>
<span class="sd">        ...         self.add = ops.Add()</span>
<span class="sd">        ...</span>
<span class="sd">        ...     def construct(self, x, y):</span>
<span class="sd">        ...         x = self.add(x, y)</span>
<span class="sd">        ...         name = &quot;x&quot;</span>
<span class="sd">        ...         self.summary(name, x)</span>
<span class="sd">        ...         return x</span>
<span class="sd">        ...</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="nd">@prim_attr_register</span>
    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Initialize HistogramSummary.&quot;&quot;&quot;</span>

        <span class="k">if</span> <span class="n">security</span><span class="o">.</span><span class="n">enable_security</span><span class="p">():</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s1">&#39;The Summary is not supported, please without `-s on` and recompile source.&#39;</span><span class="p">)</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">add_prim_attr</span><span class="p">(</span><span class="s2">&quot;side_effect_io&quot;</span><span class="p">,</span> <span class="kc">True</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">__infer__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">name</span><span class="p">,</span> <span class="n">value</span><span class="p">):</span>
        <span class="n">_check_summary_param</span><span class="p">(</span><span class="n">name</span><span class="p">,</span> <span class="n">value</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="o">.</span><span class="vm">__name__</span><span class="p">)</span>

        <span class="n">v_shape</span> <span class="o">=</span> <span class="n">value</span><span class="p">[</span><span class="s1">&#39;shape&#39;</span><span class="p">]</span>
        <span class="c1"># In the summary, the histogram value should be a tensor whose shape is not [].</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="n">v_shape</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="sa">f</span><span class="s2">&quot;For &#39;</span><span class="si">{</span><span class="bp">self</span><span class="o">.</span><span class="n">name</span><span class="si">}</span><span class="s2">&#39;, the type of &#39;value&#39; should be tensor, &quot;</span>
                             <span class="sa">f</span><span class="s2">&quot;its shape should not be [], but got </span><span class="si">{</span><span class="n">v_shape</span><span class="si">}</span><span class="s2">.&quot;</span><span class="p">)</span>

        <span class="k">return</span> <span class="n">SUMMARY_RETURN_VALUE</span></div>


<div class="viewcode-block" id="InsertGradientOf"><a class="viewcode-back" href="../../../../api_python/ops/mindspore.ops.InsertGradientOf.html#mindspore.ops.InsertGradientOf">[docs]</a><span class="k">class</span> <span class="nc">InsertGradientOf</span><span class="p">(</span><span class="n">PrimitiveWithInfer</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Attaches callback to the graph node that will be invoked on the node&#39;s gradient.</span>

<span class="sd">    Args:</span>
<span class="sd">        f (Function): MindSpore&#39;s Function. Callback function.</span>

<span class="sd">    Inputs:</span>
<span class="sd">        - **input_x** (Any) - The graph node to attach to.</span>

<span class="sd">    Outputs:</span>
<span class="sd">        Tensor, returns `input_x` directly. `InsertGradientOf` does not affect the forward result.</span>

<span class="sd">    Raises:</span>
<span class="sd">        TypeError: If `f` is not a function of mindspore.</span>

<span class="sd">    Supported Platforms:</span>
<span class="sd">        ``Ascend`` ``GPU`` ``CPU``</span>

<span class="sd">    Examples:</span>
<span class="sd">        &gt;&gt;&gt; import numpy as np</span>
<span class="sd">        &gt;&gt;&gt; from mindspore import Tensor, ops, ms_function</span>
<span class="sd">        &gt;&gt;&gt; a = Tensor(np.array([1.0]).astype(np.float32))</span>
<span class="sd">        &gt;&gt;&gt; b = Tensor(np.array([0.2]).astype(np.float32))</span>
<span class="sd">        &gt;&gt;&gt; def clip_gradient(dx):</span>
<span class="sd">        ...     ret = dx</span>
<span class="sd">        ...     if ret &gt; a:</span>
<span class="sd">        ...         ret = a</span>
<span class="sd">        ...</span>
<span class="sd">        ...     if ret &lt; b:</span>
<span class="sd">        ...         ret = b</span>
<span class="sd">        ...</span>
<span class="sd">        ...     return ret</span>
<span class="sd">        ...</span>
<span class="sd">        &gt;&gt;&gt; clip = ops.InsertGradientOf(clip_gradient)</span>
<span class="sd">        &gt;&gt;&gt; grad_all = ops.GradOperation(get_all=True)</span>
<span class="sd">        &gt;&gt;&gt; def InsertGradientOfClipDemo():</span>
<span class="sd">        ...     def clip_test(x, y):</span>
<span class="sd">        ...         x = clip(x)</span>
<span class="sd">        ...         y = clip(y)</span>
<span class="sd">        ...         c = x * y</span>
<span class="sd">        ...         return c</span>
<span class="sd">        ...</span>
<span class="sd">        ...     @ms_function</span>
<span class="sd">        ...     def f(x, y):</span>
<span class="sd">        ...         return clip_test(x, y)</span>
<span class="sd">        ...</span>
<span class="sd">        ...     def fd(x, y):</span>
<span class="sd">        ...         return grad_all(clip_test)(x, y)</span>
<span class="sd">        ...</span>
<span class="sd">        ...     print(&quot;forward: &quot;, f(Tensor(np.array([1.1]).astype(np.float32)),</span>
<span class="sd">        ...         Tensor(np.array([0.1]).astype(np.float32))))</span>
<span class="sd">        ...     print(&quot;clip_gradient:&quot;, fd(Tensor(np.array([1.1]).astype(np.float32)),</span>
<span class="sd">        ...         Tensor(np.array([0.1]).astype(np.float32))))</span>
<span class="sd">        &gt;&gt;&gt; InsertGradientOfClipDemo()</span>
<span class="sd">        forward: [0.11000001]</span>
<span class="sd">        clip_gradient: (Tensor(shape=[1], dtype=Float32, value= [ 2.00000003e-01]),</span>
<span class="sd">                        Tensor(shape=[1], dtype=Float32, value= [ 1.00000000e+00]))</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="nd">@prim_attr_register</span>
    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">f</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Initialize InsertGradientOf.&quot;&quot;&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">add_prim_attr</span><span class="p">(</span><span class="s1">&#39;side_effect_backprop&#39;</span><span class="p">,</span> <span class="kc">True</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">f</span> <span class="o">=</span> <span class="n">f</span>

    <span class="k">def</span> <span class="nf">infer_shape</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">x_shape</span><span class="p">):</span>
        <span class="k">return</span> <span class="n">x_shape</span>

    <span class="k">def</span> <span class="nf">infer_dtype</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">x_type</span><span class="p">):</span>
        <span class="k">return</span> <span class="n">x_type</span></div>


<div class="viewcode-block" id="HookBackward"><a class="viewcode-back" href="../../../../api_python/ops/mindspore.ops.HookBackward.html#mindspore.ops.HookBackward">[docs]</a><span class="k">class</span> <span class="nc">HookBackward</span><span class="p">(</span><span class="n">PrimitiveWithInfer</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    This operation is used as a tag to hook gradient in intermediate variables. Note that this function</span>
<span class="sd">    is only supported in Pynative Mode.</span>

<span class="sd">    Note:</span>
<span class="sd">        The hook function must be defined like `hook_fn(grad) -&gt; Tensor or None`,</span>
<span class="sd">        where grad is the gradient passed to the primitive and gradient may be</span>
<span class="sd">        modified and passed to next primitive. The difference between a hook function and</span>
<span class="sd">        callback of InsertGradientOf is that a hook function is executed in the python</span>
<span class="sd">        environment while callback will be parsed and added to the graph.</span>

<span class="sd">    Args:</span>
<span class="sd">        hook_fn (Function): Python function. hook function.</span>
<span class="sd">        cell_id (str): Used to identify whether the function registered by the hook is actually registered on</span>
<span class="sd">                       the specified Cell. Where the Cell is an object. For example, &#39;nn.Add&#39; is a Cell object.</span>
<span class="sd">                       The default value of cell_id is &quot;, in this case, the system will automatically register</span>
<span class="sd">                       when registering. Add a value of cell_id, the value of cell_id currently does not support</span>
<span class="sd">                       custom values.</span>

<span class="sd">    Inputs:</span>
<span class="sd">        - **inputs** (Tensor) - The variable to hook.</span>

<span class="sd">    Raises:</span>
<span class="sd">        TypeError: If `inputs` are not a Tensor.</span>
<span class="sd">        TypeError: If `hook_fn` is not a function of python.</span>

<span class="sd">    Supported Platforms:</span>
<span class="sd">        ``Ascend`` ``GPU`` ``CPU``</span>

<span class="sd">    Examples:</span>
<span class="sd">        &gt;&gt;&gt; import mindspore</span>
<span class="sd">        &gt;&gt;&gt; from mindspore import context</span>
<span class="sd">        &gt;&gt;&gt; from mindspore import Tensor</span>
<span class="sd">        &gt;&gt;&gt; from mindspore import ops</span>
<span class="sd">        &gt;&gt;&gt; from mindspore.ops import GradOperation</span>
<span class="sd">        &gt;&gt;&gt; context.set_context(mode=context.PYNATIVE_MODE, device_target=&quot;GPU&quot;)</span>
<span class="sd">        &gt;&gt;&gt; def hook_fn(grad_out):</span>
<span class="sd">        ...     print(grad_out)</span>
<span class="sd">        ...</span>
<span class="sd">        &gt;&gt;&gt; grad_all = GradOperation(get_all=True)</span>
<span class="sd">        &gt;&gt;&gt; hook = ops.HookBackward(hook_fn)</span>
<span class="sd">        &gt;&gt;&gt; def hook_test(x, y):</span>
<span class="sd">        ...     z = x * y</span>
<span class="sd">        ...     z = hook(z)</span>
<span class="sd">        ...     z = z * y</span>
<span class="sd">        ...     return z</span>
<span class="sd">        ...</span>
<span class="sd">        &gt;&gt;&gt; def backward(x, y):</span>
<span class="sd">        ...     return grad_all(hook_test)(x, y)</span>
<span class="sd">        ...</span>
<span class="sd">        &gt;&gt;&gt; output = backward(Tensor(1, mindspore.float32), Tensor(2, mindspore.float32))</span>
<span class="sd">        (Tensor(shape=[], dtype=Float32, value= 2),)</span>
<span class="sd">        &gt;&gt;&gt; print(output)</span>
<span class="sd">        (Tensor(shape=[], dtype=Float32, value= 4), Tensor(shape=[], dtype=Float32, value= 4))</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">hook_fn</span><span class="p">,</span> <span class="n">cell_id</span><span class="o">=</span><span class="s2">&quot;&quot;</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Initialize HookBackward.&quot;&quot;&quot;</span>
        <span class="nb">super</span><span class="p">(</span><span class="n">HookBackward</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="o">.</span><span class="vm">__name__</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">add_prim_attr</span><span class="p">(</span><span class="s2">&quot;cell_id&quot;</span><span class="p">,</span> <span class="n">cell_id</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">init_attrs</span><span class="p">[</span><span class="s2">&quot;cell_id&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">cell_id</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">hook_fn</span><span class="p">,</span> <span class="p">(</span><span class="n">FunctionType</span><span class="p">,</span> <span class="n">MethodType</span><span class="p">)):</span>
            <span class="k">raise</span> <span class="ne">TypeError</span><span class="p">(</span><span class="sa">f</span><span class="s2">&quot;For &#39;</span><span class="si">{</span><span class="bp">self</span><span class="o">.</span><span class="n">name</span><span class="si">}</span><span class="s2">&#39;, the type of &#39;hook_fn&#39; should be python function, &quot;</span>
                            <span class="sa">f</span><span class="s2">&quot;but got </span><span class="si">{</span><span class="nb">type</span><span class="p">(</span><span class="n">hook_fn</span><span class="p">)</span><span class="si">}</span><span class="s2">.&quot;</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">register_hook</span><span class="p">(</span><span class="n">hook_fn</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">cell_id</span> <span class="o">=</span> <span class="n">cell_id</span>

    <span class="k">def</span> <span class="nf">infer_shape</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">*</span><span class="n">inputs_shape</span><span class="p">):</span>
        <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">inputs_shape</span><span class="p">)</span> <span class="o">==</span> <span class="mi">1</span><span class="p">:</span>
            <span class="k">return</span> <span class="n">inputs_shape</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
        <span class="k">return</span> <span class="n">inputs_shape</span>

    <span class="k">def</span> <span class="nf">infer_dtype</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">*</span><span class="n">inputs_type</span><span class="p">):</span>
        <span class="k">for</span> <span class="n">dtype</span> <span class="ow">in</span> <span class="n">inputs_type</span><span class="p">:</span>
            <span class="n">validator</span><span class="o">.</span><span class="n">check_subclass</span><span class="p">(</span><span class="s2">&quot;input&quot;</span><span class="p">,</span> <span class="n">dtype</span><span class="p">,</span> <span class="p">[</span><span class="n">mstype</span><span class="o">.</span><span class="n">tensor</span><span class="p">],</span> <span class="bp">self</span><span class="o">.</span><span class="n">name</span><span class="p">)</span>
        <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">inputs_type</span><span class="p">)</span> <span class="o">==</span> <span class="mi">1</span><span class="p">:</span>
            <span class="k">return</span> <span class="n">inputs_type</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
        <span class="k">return</span> <span class="n">inputs_type</span></div>


<div class="viewcode-block" id="Print"><a class="viewcode-back" href="../../../../api_python/ops/mindspore.ops.Print.html#mindspore.ops.Print">[docs]</a><span class="k">class</span> <span class="nc">Print</span><span class="p">(</span><span class="n">PrimitiveWithInfer</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Outputs the tensor or string to stdout. The outputs are printed to screen by default.</span>
<span class="sd">    It can also be saved in a file by setting the parameter  `print_file_path` in `context`.</span>
<span class="sd">    Once set, the output will be saved in the file specified by print_file_path.</span>
<span class="sd">    parse_print can be employed to reload the data.</span>
<span class="sd">    For more information, please refer to :func:`mindspore.context.set_context` and :func:`mindspore.parse_print`.</span>

<span class="sd">    Note:</span>
<span class="sd">        In pynative mode, please use python print function.</span>
<span class="sd">        In graph mode, the bool, int and float would be converted into Tensor to print,</span>
<span class="sd">        str remains unchanged.</span>

<span class="sd">    Inputs:</span>
<span class="sd">        - **input_x** (Union[Tensor, bool, int, float, str]) - The graph node to attach to.</span>
<span class="sd">          Supports multiple inputs which are separated by &#39;,&#39;.</span>

<span class="sd">    Outputs:</span>
<span class="sd">        Tensor, has the same data type and shape as original `input_x`.</span>

<span class="sd">    Raises:</span>
<span class="sd">        TypeError: If `input_x` is not one of the following: Tensor, bool, int, float, str.</span>

<span class="sd">    Supported Platforms:</span>
<span class="sd">        ``Ascend`` ``GPU``</span>

<span class="sd">    Examples:</span>
<span class="sd">        &gt;&gt;&gt; class PrintDemo(nn.Cell):</span>
<span class="sd">        ...     def __init__(self):</span>
<span class="sd">        ...         super(PrintDemo, self).__init__()</span>
<span class="sd">        ...         self.print = ops.Print()</span>
<span class="sd">        ...</span>
<span class="sd">        ...     def construct(self, x, y):</span>
<span class="sd">        ...         self.print(&#39;Print Tensor x and Tensor y:&#39;, x, y)</span>
<span class="sd">        ...         return x</span>
<span class="sd">        ...</span>
<span class="sd">        &gt;&gt;&gt; x = Tensor(np.ones([2, 1]).astype(np.int32))</span>
<span class="sd">        &gt;&gt;&gt; y = Tensor(np.ones([2, 2]).astype(np.int32))</span>
<span class="sd">        &gt;&gt;&gt; net = PrintDemo()</span>
<span class="sd">        &gt;&gt;&gt; result = net(x, y)</span>
<span class="sd">        Print Tensor x and Tensor y:</span>
<span class="sd">        Tensor(shape=[2, 1], dtype=Int32, value=</span>
<span class="sd">        [[1]</span>
<span class="sd">         [1]])</span>
<span class="sd">        Tensor(shape=[2, 2], dtype=Int32, value=</span>
<span class="sd">        [[1 1]</span>
<span class="sd">         [1 1]])</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="nd">@prim_attr_register</span>
    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Initialize Print.&quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="n">security</span><span class="o">.</span><span class="n">enable_security</span><span class="p">():</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span>
                <span class="s1">&#39;The Print is not supported, please without `-s on` and recompile source.&#39;</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">add_prim_attr</span><span class="p">(</span><span class="s2">&quot;side_effect_io&quot;</span><span class="p">,</span> <span class="kc">True</span><span class="p">)</span>

    <span class="k">def</span> <span class="fm">__call__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">):</span>
        <span class="k">for</span> <span class="n">arg</span> <span class="ow">in</span> <span class="n">args</span><span class="p">:</span>
            <span class="nb">print</span><span class="p">(</span><span class="n">arg</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">infer_shape</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">*</span><span class="n">inputs</span><span class="p">):</span>
        <span class="k">return</span> <span class="p">[</span><span class="mi">1</span><span class="p">]</span>

    <span class="k">def</span> <span class="nf">infer_dtype</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">*</span><span class="n">inputs</span><span class="p">):</span>
        <span class="c1"># check argument types except the last one (io state).</span>
        <span class="k">for</span> <span class="n">ele</span> <span class="ow">in</span> <span class="n">inputs</span><span class="p">[:</span><span class="o">-</span><span class="mi">1</span><span class="p">]:</span>
            <span class="n">validator</span><span class="o">.</span><span class="n">check_subclass</span><span class="p">(</span><span class="s2">&quot;input&quot;</span><span class="p">,</span> <span class="n">ele</span><span class="p">,</span>
                                     <span class="p">[</span><span class="n">mstype</span><span class="o">.</span><span class="n">tensor</span><span class="p">,</span> <span class="n">mstype</span><span class="o">.</span><span class="n">int_</span><span class="p">,</span> <span class="n">mstype</span><span class="o">.</span><span class="n">float_</span><span class="p">,</span> <span class="n">mstype</span><span class="o">.</span><span class="n">bool_</span><span class="p">,</span> <span class="n">mstype</span><span class="o">.</span><span class="n">string</span><span class="p">],</span>
                                     <span class="bp">self</span><span class="o">.</span><span class="n">name</span><span class="p">)</span>
        <span class="k">return</span> <span class="n">mstype</span><span class="o">.</span><span class="n">int32</span></div>


<span class="k">class</span> <span class="nc">Assert</span><span class="p">(</span><span class="n">PrimitiveWithInfer</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Asserts that the given condition is True.</span>
<span class="sd">    If input condition evaluates to false, print the list of tensor in data.</span>

<span class="sd">    Args:</span>
<span class="sd">        summarize (int): Print this many entries of each tensor.</span>

<span class="sd">    Inputs:</span>
<span class="sd">        - **condition** [Union[Tensor[bool], bool]] - The condition to evaluate.</span>
<span class="sd">        - **input_data** (Union(tuple[Tensor], list[Tensor])) - The tensors to print out when condition is false.</span>

<span class="sd">    Raises:</span>
<span class="sd">        TypeError: If `summarize` is not an int.</span>
<span class="sd">        TypeError: If `condition` is neither a Tensor nor a bool.</span>
<span class="sd">        TypeError: If `input_data` is neither a tuple nor a list.</span>

<span class="sd">    Examples:</span>
<span class="sd">        &gt;&gt;&gt; class AssertDemo(nn.Cell):</span>
<span class="sd">        ...     def __init__(self):</span>
<span class="sd">        ...         super(AssertDemo, self).__init__()</span>
<span class="sd">        ...         self.assert1 = ops.Assert(summarize=10)</span>
<span class="sd">        ...         self.add = ops.Add()</span>
<span class="sd">        ...</span>
<span class="sd">        ...     def construct(self, x, y):</span>
<span class="sd">        ...         data = self.add(x, y)</span>
<span class="sd">        ...         self.assert1(True, [data])</span>
<span class="sd">        ...         return data</span>
<span class="sd">        ...</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="nd">@prim_attr_register</span>
    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">summarize</span><span class="o">=</span><span class="mi">3</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Initialize Assert&quot;&quot;&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">summarize</span> <span class="o">=</span> <span class="n">validator</span><span class="o">.</span><span class="n">check_value_type</span><span class="p">(</span><span class="s2">&quot;summarize&quot;</span><span class="p">,</span> <span class="n">summarize</span><span class="p">,</span> <span class="p">[</span><span class="nb">int</span><span class="p">],</span> <span class="bp">self</span><span class="o">.</span><span class="n">name</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">infer_shape</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">condition</span><span class="p">,</span> <span class="n">inputs</span><span class="p">):</span>
        <span class="n">condition_len</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">condition</span><span class="p">)</span>
        <span class="n">validator</span><span class="o">.</span><span class="n">check_int</span><span class="p">(</span><span class="n">condition_len</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="n">Rel</span><span class="o">.</span><span class="n">LE</span><span class="p">,</span> <span class="s2">&quot;condition&#39;s rank&quot;</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">name</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">condition_len</span> <span class="o">==</span> <span class="mi">1</span><span class="p">:</span>
            <span class="n">validator</span><span class="o">.</span><span class="n">check_equal_int</span><span class="p">(</span><span class="n">condition</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="mi">1</span><span class="p">,</span> <span class="s2">&quot;condition[0]&quot;</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">name</span><span class="p">)</span>
        <span class="k">return</span> <span class="p">[</span><span class="mi">1</span><span class="p">]</span>

    <span class="k">def</span> <span class="nf">infer_dtype</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">condition</span><span class="p">,</span> <span class="n">inputs</span><span class="p">):</span>
        <span class="n">validator</span><span class="o">.</span><span class="n">check_scalar_or_tensor_types_same</span><span class="p">({</span><span class="s2">&quot;condition&quot;</span><span class="p">:</span> <span class="n">condition</span><span class="p">},</span> <span class="p">[</span><span class="n">mstype</span><span class="o">.</span><span class="n">bool_</span><span class="p">],</span> <span class="bp">self</span><span class="o">.</span><span class="n">name</span><span class="p">)</span>
        <span class="k">for</span> <span class="n">dtype</span> <span class="ow">in</span> <span class="n">inputs</span><span class="p">:</span>
            <span class="n">validator</span><span class="o">.</span><span class="n">check_subclass</span><span class="p">(</span><span class="s2">&quot;input&quot;</span><span class="p">,</span> <span class="n">dtype</span><span class="p">,</span> <span class="p">[</span><span class="n">mstype</span><span class="o">.</span><span class="n">tensor</span><span class="p">],</span> <span class="bp">self</span><span class="o">.</span><span class="n">name</span><span class="p">)</span>
        <span class="k">return</span> <span class="n">mstype</span><span class="o">.</span><span class="n">int32</span>
</pre></div>

           </div>
           
          </div>
          <footer>

  <hr/>

  <div role="contentinfo">
    <p>
        &#169; Copyright 2021, MindSpore.

    </p>
  </div>
    
    
    
    Built with <a href="https://www.sphinx-doc.org/">Sphinx</a> using a
    
    <a href="https://github.com/readthedocs/sphinx_rtd_theme">theme</a>
    
    provided by <a href="https://readthedocs.org">Read the Docs</a>. 

</footer>
        </div>
      </div>

    </section>

  </div>
  

  <script type="text/javascript">
      jQuery(function () {
          SphinxRtdTheme.Navigation.enable(true);
      });
  </script>

  
  
    
   

</body>
</html>